﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using Enterprise.Model.WorkFlow;
using Enterprise.Service.WorkFlow;
using Enterprise.Infrastructure;

namespace Enterprise.UI.Web.Manage.WorkFlow
{
    /// <summary>
    /// WorkFlowUnCheck 的摘要说明
    /// </summary>
    public class WorkFlowUnCheck : IHttpHandler
    {
        /// <summary>
        ///  返回方式，0默认返回待办数字 1返回待办分类列表
        /// </summary>
        int TypeId = (int)Utility.sink("TypeId", Utility.MethodType.Get, 0, 0, Utility.DataType.Int);
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            WorkFlowProcessService wfService = new WorkFlowProcessService();
            List<WorkFlowProcessEntity> list = wfService.WorkFlowProcessList().Where(p => p.PISCHECK == 0 && p.PUSERID == Utility.Get_UserId).ToList();
            if (TypeId == 0)
            {
                Service.Meeting.MeetingService mService = new Service.Meeting.MeetingService();
                int mCount = mService.MeetingUnCheck(Utility.Get_UserId).Count;
                context.Response.Write("<span class=\"numberTop\">" + (list.Count +mCount)+ "</span>");
            }
            else
            {
                StringBuilder sb = new StringBuilder();
                int UserId = Utility.Get_UserId;
                //公文办理
                Enterprise.Service.OfficeDocument.OfficeDocService odService = new Service.OfficeDocument.OfficeDocService();
                int odCount = odService.OfficeDocumentUnCheck(UserId).Count;
                if (odCount > 0)
                {
                    sb.AppendFormat("<a href=\"/Modules/OfficeDocument/OfficeDocumentIndex.aspx\">需要我办理的公文流程</a>&nbsp;&nbsp;&nbsp;&nbsp;(<font color=\"red\">{0}</font>)", odCount);
                }

                //差旅办理
                Service.BusiTravel.BusiTravelService btService = new Service.BusiTravel.BusiTravelService();
                int btCount = btService.BusiTravelUnCheck(UserId).Count;
                if (btCount > 0)
                {
                    sb.AppendFormat("<br /><a href=\"/Modules/BusiTravel/CheckIndex.aspx\">需要我审批的差旅申请单</a>&nbsp;&nbsp;&nbsp;&nbsp;(<font color=\"red\">{0}</font>)", btCount);
                }

                //会议签收待办
                Service.Meeting.MeetingService mService = new Service.Meeting.MeetingService();
                int mCount = mService.MeetingUnCheck(UserId).Count;
                if (mCount > 0)
                {
                    sb.AppendFormat("<br /><a href=\"/Modules/Meeting/CheckIndex.aspx\">需要我签收的会议通知单</a>&nbsp;&nbsp;&nbsp;&nbsp;(<font color=\"red\">{0}</font>)", mCount);
                }
                context.Response.Write(sb.ToString());
            }
            
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}